#pragma once
#include <map>
#include <string>
#include <functional>
#include <memory>
#include "Script.hpp"

class ScriptManager {
public:
    // 注册脚本类
    template<typename T>
    void RegisterScript(const std::string& name) {
        static_assert(std::is_base_of<Script, T>::value, 
                     "T must inherit from Script");
        m_scriptFactories[name] = []() {
            return std::make_shared<T>();
        };
    }
    
    // 创建脚本实例
    std::shared_ptr<Script> CreateScript(const std::string& name) {
        auto it = m_scriptFactories.find(name);
        if (it != m_scriptFactories.end()) {
            return it->second();
        }
        return nullptr;
    }
    
    // 获取所有注册的脚本名称
    std::vector<std::string> GetRegisteredScriptNames() const {
        std::vector<std::string> names;
        for (const auto& pair : m_scriptFactories) {
            names.push_back(pair.first);
        }
        return names;
    }
    
    // 获取脚本的属性描述符
    std::vector<PropertyDescriptor> GetScriptProperties(const std::string& name) {
        auto script = CreateScript(name);
        if (script) {
            return script->GetProperties();
        }
        return {};
    }
    
private:
    std::map<std::string, std::function<std::shared_ptr<Script>()>> m_scriptFactories;
};